const { Service } = require("egg");

const nodemailer = require("nodemailer");
// 你的邮箱用户名
const userEmail = "xxxxxxxxx.com";

const transporter = nodemailer.createTransport({
      host: "smtp.126.com",
      port: 25,
      auth: {
            user: userEmail,
            pass: "xxxxxxxxx", // 如果你是网易邮箱，这个pass就可能是授权密码
      },
});

class ToolService extends Service {
      async sendMail(email, subject, text, html) {
            try {
                  await transporter.sendMail({
                        from: userEmail,
                        cc: userEmail,
                        to: email,
                        subject,
                        text,
                        html,
                  });

                  return { success: true, message: "发送成功" };
            } catch (e) {
                  return { success: false, message: e };
            }
      }


}

module.exports = ToolService;
